﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
using System.Collections;
namespace PTTK11_HuongRung
{
    public partial class frmMonAn : Form
    {
        MonAnBUS maBUS;
       // ArrayList dsThucDon;
        public int id;

        public frmMonAn()
        {
            InitializeComponent();
        }

        private void frmMonAn_Load(object sender, EventArgs e)
        {
            btnDangNhap.Text = "Đăng Xuất";
            NhanVienBUS nvBus = new NhanVienBUS();
            NhanVienDTO nvDto = new NhanVienDTO();
            nvDto = nvBus.GetThongTinNhanVien(Secssion.MaNV);
            txtHoTen.Text = nvDto.TENNHANVIEN.Trim();
            LoaiNhanVienBUS lnvbus = new LoaiNhanVienBUS();
            txtMaNV.Text = lnvbus.GetTenLoaiNV(nvDto.LOAINHANVIEN);
            reLoad();
        }

        private void reLoad()
        {
            MonAnBUS bus = new MonAnBUS();
            dgvDanhSach.DataSource = bus.GetDSMonAn();
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            MonAnBUS bus = new MonAnBUS();
            dgvDanhSach.DataSource = bus.TimKiem(txtTuKhoa.Text.Trim());
        }

  

        private void dgvDanhSach_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
                return;

            id = int.Parse(dgvDanhSach.Rows[e.RowIndex].Cells[0].Value.ToString());
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmThemMonAn frm = new frmThemMonAn();

            frm.ShowDialog();
            this.Close();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmQuanLy frm = new frmQuanLy();
            frm.ShowDialog();
            this.Close();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            this.Hide();
            frmCapNhatMonAn frm = new frmCapNhatMonAn();
            frm.ShowDialog();
            this.Close();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (id == 0)
            {
                MessageBox.Show("Bạn chưa chọn dòng cần xóa.");
                return;
            }
            MonAnDTO maDTO = new MonAnDTO();
            maBUS.ThucDon = maDTO;
            maBUS.XoaMonAn(id);
            reLoad();
        }

        

        private void timer_Tick(object sender, EventArgs e)
        {
            ThoiGian.Text = DateTime.Now.ToString("dd/MM/yy HH:mm:ss");
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (btnDangNhap.Text.Trim().CompareTo("Đăng Xuất") == 0)
            {
                btnDangNhap.Text = "Đăng Nhâp";
                Secssion.MaNV = "";
                Secssion.MaKhac = "";

                txtHoTen.Text = "";
                txtMaNV.Text = "";
                this.Hide();
                frmQuanLy frm = new frmQuanLy();
                frm.ShowDialog();
                this.Close();
            }
            else
            {
                this.Hide();
                frmDangNhap frm = new frmDangNhap();
                frm.ShowDialog();
                this.Close();
            }
        }
    }
}
